#include "DataCollectionTypes.h"

#include "XString.h"
#include "Exception.h"
#include "RegistryHelper.h"


#define REGISTRY_ROOT_KEY							_T("Config\\Collector\\DataTypes")

#define REGISTRY_VALUE_FILE_EVENTS					_T("FileEvents")
#define REGISTRY_VALUE_MEMORY_EVENTS				_T("VirMemEvents")
#define REGISTRY_VALUE_THREAD_EVENTS				_T("ThreadEvents")
#define REGISTRY_VALUE_WINDOW_EVENTS				_T("WindowEvents")
#define REGISTRY_VALUE_NETWORK_EVENTS				_T("NetworkEvents")
#define REGISTRY_VALUE_SYNC_EVENTS					_T("SyncEvents")

#define REGISTRY_MONITORING_ENABLED_VALUE			1
#define REGISTRY_MONITORING_DISABLED_VALUE			0


using namespace platform;

namespace config {

DataCollectionTypes::DataCollectionTypes(void) {
	try {
		RegistryHelper::RegistryKey key(RegistryHelper::RK_ABPA_BASE, REGISTRY_ROOT_KEY);
		m_sendFileEvents = (key.getInt32Value(REGISTRY_VALUE_FILE_EVENTS) == REGISTRY_MONITORING_ENABLED_VALUE);
		m_sendMemoryEvents = (key.getInt32Value(REGISTRY_VALUE_MEMORY_EVENTS) == REGISTRY_MONITORING_ENABLED_VALUE);
		m_sendThreadEvents = (key.getInt32Value(REGISTRY_VALUE_THREAD_EVENTS) == REGISTRY_MONITORING_ENABLED_VALUE);
		m_sendWindowEvents = (key.getInt32Value(REGISTRY_VALUE_WINDOW_EVENTS) == REGISTRY_MONITORING_ENABLED_VALUE);
		m_sendNetworkEvents = (key.getInt32Value(REGISTRY_VALUE_NETWORK_EVENTS) == REGISTRY_MONITORING_ENABLED_VALUE);
		m_sendSyncEvents = (key.getInt32Value(REGISTRY_VALUE_SYNC_EVENTS) == REGISTRY_MONITORING_ENABLED_VALUE);
	} catch (Exception &) {
		m_sendFileEvents = false;
		m_sendMemoryEvents = false;
		m_sendThreadEvents = false;
		m_sendWindowEvents = false;
		m_sendNetworkEvents = false;
		m_sendSyncEvents = false;
	}
}


void DataCollectionTypes::do_save(void) const {
	RegistryHelper::RegistryKey key(RegistryHelper::RK_ABPA_BASE, REGISTRY_ROOT_KEY);

	key.setValue(REGISTRY_VALUE_FILE_EVENTS, 
		(m_sendFileEvents ? REGISTRY_MONITORING_ENABLED_VALUE : REGISTRY_MONITORING_DISABLED_VALUE));
	key.setValue(REGISTRY_VALUE_MEMORY_EVENTS, 
		(m_sendMemoryEvents ? REGISTRY_MONITORING_ENABLED_VALUE : REGISTRY_MONITORING_DISABLED_VALUE));
	key.setValue(REGISTRY_VALUE_THREAD_EVENTS, 
		(m_sendThreadEvents ? REGISTRY_MONITORING_ENABLED_VALUE : REGISTRY_MONITORING_DISABLED_VALUE));
	key.setValue(REGISTRY_VALUE_WINDOW_EVENTS, 
		(m_sendWindowEvents ? REGISTRY_MONITORING_ENABLED_VALUE : REGISTRY_MONITORING_DISABLED_VALUE));
	key.setValue(REGISTRY_VALUE_NETWORK_EVENTS, 
		(m_sendNetworkEvents ? REGISTRY_MONITORING_ENABLED_VALUE : REGISTRY_MONITORING_DISABLED_VALUE));
	key.setValue(REGISTRY_VALUE_SYNC_EVENTS, 
		(m_sendSyncEvents ? REGISTRY_MONITORING_ENABLED_VALUE : REGISTRY_MONITORING_DISABLED_VALUE));
}

}  // end namespace
